package org.lmind.example.util.common;

import java.io.ByteArrayInputStream;
import java.io.IOException;

import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.ws.Endpoint;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.EntityResolver;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

public class Test {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {

			DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
			
			Document doc = db.parse(new ByteArrayInputStream("<r><a/><a/><a/></r>".getBytes("utf-8")));
			
			String name = doc.getDocumentElement().getNodeName();
			
			XPathFactory x = XPathFactory.newInstance();
			XPath path = x.newXPath();
			XPathExpression e = path.compile("/r/*");
			NodeList o = (NodeList)e.evaluate(doc, XPathConstants.NODESET);
			
			for (int i = 0; i < o.getLength(); i++) {
			 	Node node = o.item(i);
			 	node.toString();
			}
			
			//org.dom4j.Element
			
			for (Class<?> clazz : o.getClass().getInterfaces()) {
				System.out.println(clazz);
			}
			o.toString();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
